<!---->
<template>
    <div class="common_header">
        <x-header :left-options="{showBack: showBack,backText: backText,preventGoBack : true}" @on-click-back="goback">
            <span>{{title}}</span>
            <span style="display: none;">{{currentName}}</span>
        </x-header>
    </div>
</template>

<script>
    import {XHeader} from 'vux'

    export default {
        name: "",
        components: {
            XHeader,
        },
        props: {
            title: {
                type: String,
                default: '',
            },
            backText: {
                type: String,
                default: '',
            },
            showBack: {
                type: Boolean,
                default: true,
            },
        },
        data() {
            return {
                historyPathList: this.$store.state.user.historyPathList,
            }
        },

        created() {

        },

        computed: {
            currentName() {
                if (this.$route.name === 'home' || this.$route.name === 'companyInfo' || this.$route.name === 'userInfo') {
                    this.historyPathList = [];
                } else {
                    let _check = false;
                    for (let i in this.historyPathList) {
                        let item = this.historyPathList[i];
                        if (item.name === this.$route.name) {
                            this.historyPathList[i] = this.$route;
                            _check = true;
                            break;
                        }
                    }

                    if (!_check) {
                        this.historyPathList.push(this.$route);
                    }
                }

                this.$store.dispatch('changeHistoryPathList', this.historyPathList)
                return this.$route.name;
            },
        },

        methods: {
            // 返回
            goback() {
                switch (this.currentName) {
                    case 'companyDetail':
                        this.$tools.goPage('companyInfo')
                        break;
                    case 'requiredDetail' :
                    case 'optionDetail' :
                    case 'addproduct' :
                        this.go('companyDetail')
                        break;
                    case 'accoutInfo':
                    case 'addmember':
                    case 'selecthouse':
                        this.$tools.goPage('home')
                        break;
                    case 'edittudi' :
                    case 'editzhengdi' :
                    case 'editsdqtx' :
                    case 'edithouse' :
                    case 'editfuken' :
                    case 'editchanye' :
                    case 'editbaseInfo' :
                        this.go('accoutInfo')
                        break;
                    case 'memberOptionInfo':
                    case 'memberSpecialInfo':
                    case 'petition':
                    case 'dispute':
                    case 'subsidy':
                        this.go('addmember')
                        break;
                    case 'subsidytype':
                        this.go('subsidy')
                        break;
                    case 'resetPwd':
                    case 'problem':
                    case 'aboutUs':
                        this.$tools.goPage('userInfo')
                        break;

                }
            },

            go(param) {
                for (let i in this.historyPathList) {
                    let item = this.historyPathList[i];
                    if (item.name === param) {
                        this.$tools.goPage_query(param, item.query)
                        break;
                    }
                }

            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/less">
    .vux-header {
        top: 0 !important;
        background-color: #6c84e5 !important;
    }

    .vux-header .vux-header-left .left-arrow:before {
        border-left: 2px solid #fff !important;
        border-top: 2px solid #fff !important;
    }
</style>
